import os
import subprocess
from pytablewriter import MarkdownTableWriter




writer = MarkdownTableWriter()
writer.table_name = "linear vs boost vs mlp"
writer.headers = ["y", "linear", "boost", "mlp"]

table = []

def run(cmd):
    p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
    stdout = p.communicate()[0].decode('utf-8')
    capture = stdout.splitlines()[-2:]
    return '\n'.join(capture)

ys = [
    "",
    "AskToBid3s",
    "AskToBid5s",
    "AskToBid10s",
    "AskToBid30s",
    "BidToAsk3s",
    "BidToAsk5s",
    "BidToAsk10s",
    "BidToAsk30s",
]
for y in range(1, 9):
    with open('cc/appcoin2/experimental/donggu/strat/y.py', 'w') as f:
        f.write('Y = %d' % y)
    a = run('python cc/appcoin2/experimental/donggu/strat/sk.py'.split())
    b = run('python cc/appcoin2/experimental/donggu/strat/train_light.py'.split())
#    c = run('python cc/appcoin2/experimental/donggu/strat/train.py'.split())
    c = ""
    table.append((ys[y],a,b,c))

writer.value_matrix = table
writer.write_table()
